package com.twu.biblioteca.menus;

import com.twu.biblioteca.Book;
import com.twu.biblioteca.BookList;
import com.twu.biblioteca.InputController;
import com.twu.biblioteca.OutputController;

import java.io.IOException;

public class ReserveBookMenu implements Menu {


    private final OutputController outputController;
    private final InputController inputController;
    private final BookList books;
    private int bookIndex;

    public ReserveBookMenu( OutputController outputController, InputController inputController, BookList books) {

        this.outputController = outputController;
        this.inputController = inputController;
        this.books = books;
    }

    public void displayMenu() {
        outputController.drawOptions(books.getOptions());
    }

    @Override
    public void runCommand() {
        final Book book = books.get(bookIndex);
        if (book.reserveBook()) {
            outputController.drawMessage("Thank You! Enjoy the book.");
        } else {
            outputController.drawMessage("Sorry we don't have that book yet or it is checked out.");
        }
    }

    @Override
    public void getInput() throws IOException {
        bookIndex = inputController.readOption(books.size());

    }

    @Override
    public int getNextMenu() {
        return 1;
    }

    @Override
    public boolean mustBeLoggedIn() {
        return true;
    }


}
